 
package ibms_rcp.worker.parts;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;

public class QueryPart {
	//姓名
	private Text nameText;
	//部门
	private ComboViewer depComboViewer;
	private Combo depCombo;
	//查询
	private Button queryButton;	
	
	private TableViewer tableViewer;
	private Table table;
	
	@Inject
	public QueryPart(Composite parent) {
		//TODO Your code here
	}
	
	@PostConstruct
	public void postConstruct(final Composite parent) {
		GridLayout layout = new GridLayout(1, false);
		layout.marginWidth = 10;
		layout.marginHeight = 10;
		parent.setLayout(layout);
		
		Label title = new Label(parent, SWT.NONE);
		title.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD));
		title.setText("员工查询");
		
		Composite queryComposite = new Composite(parent, SWT.BORDER);
		queryComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		queryComposite.setLayout(new GridLayout(5, false));
		
		//姓名
		Label nameLabel = new Label(queryComposite, SWT.RIGHT);
		nameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		nameLabel.setText("姓名：");
		nameText = new Text(queryComposite, SWT.BORDER);
		nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		// 部门
		Label depLabel = new Label(queryComposite, SWT.RIGHT);
		depLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		depLabel.setText("部门：");
		depComboViewer = new ComboViewer(queryComposite, SWT.READ_ONLY);
		depCombo = depComboViewer.getCombo();
		depCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
		depComboViewer.setContentProvider(ArrayContentProvider
				.getInstance());
		depComboViewer.setLabelProvider(new LabelProvider() {
			@Override
			public String getText(Object element) {
				//TODO 得到部门text
//						if (element instanceof Building) {
//							Building building = (Building) element;
//							return building.getEms_name();
//						}
				return super.getText(element);
			}
		});
		// TODO 获取部门数据
		
		//查询按钮
		queryButton = new Button(queryComposite, SWT.NONE);
		queryButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
				false, 1, 1));
		queryButton.setText("查询");
		
		tableViewer = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION);
		table = tableViewer.getTable();
		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		TableViewerColumn seqViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn seqTableColumn = seqViewerColumn.getColumn();
		seqTableColumn.setResizable(false);
		seqTableColumn.setAlignment(SWT.CENTER);
		seqTableColumn.setWidth(40);
		seqTableColumn.setText("序号");
		
		TableViewerColumn nameViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn nameTableColumn = nameViewerColumn.getColumn();
		nameTableColumn.setAlignment(SWT.CENTER);
		nameTableColumn.setWidth(100);
		nameTableColumn.setText("姓名");
		
		TableViewerColumn depViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn depTableColumn = depViewerColumn.getColumn();
		depTableColumn.setResizable(false);
		depTableColumn.setAlignment(SWT.CENTER);
		depTableColumn.setWidth(100);
		depTableColumn.setText("部门");
		
		TableViewerColumn posViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn posTableColumn = posViewerColumn.getColumn();
		posTableColumn.setResizable(false);
		posTableColumn.setAlignment(SWT.CENTER);
		posTableColumn.setWidth(100);
		posTableColumn.setText("职务");
		
		TableViewerColumn telViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn telTableColumn = telViewerColumn.getColumn();
		telTableColumn.setResizable(false);
		telTableColumn.setAlignment(SWT.CENTER);
		telTableColumn.setWidth(100);
		telTableColumn.setText("联系电话");
	}
	
	
	@PreDestroy
	public void preDestroy() {
		//TODO Your code here
	}
	
	
	
}